package com.crm.system.controller.cluePoolManager;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.crm.common.model.DataResponse;
import com.crm.common.model.DhResponse;
import com.crm.common.model.Enum.ResponseCodeEnum;
import com.crm.model.vo.cluePoolManager.CluePoolCompanyVO;
import com.crm.system.service.cluePoolManager.CluePoolCompanyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * 线索池公司、个人权限
 * @author luojie
 * @date 2021/1/12 21:45
 */
@RestController
@RequestMapping("/cluePoolCompany")
@Slf4j
public class CluePoolCompanyController {

    @Autowired
    private CluePoolCompanyService cluePoolCompanyService;

    /**
     * 根据线索池ID查询人员(私有池)
     * @param cluePollId  ---线索池ID
     * @return
     */
    @GetMapping("/selectPersonByDistributePermission")
    public DataResponse selectPersonByDistributePermission(@RequestParam(value="cluePollId",required = true)String cluePollId){
        try{
            List<Map<String, Object>> companyList = cluePoolCompanyService.selectPersonByDistributePermission(cluePollId);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),companyList);
        }catch(Exception e){
            log.error("cluePoolCompany selectPersonByDistributePermission error:", e);
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        }
    }

    /**
     * 根据线索池ID查询公司(私有池)
     * @param cluePollId  ---线索池ID
     * @return
     */
    @GetMapping("/selectCompanyByDistributePermission")
    public DataResponse selectCompanyByDistributePermission(@RequestParam(value="cluePollId",required = true)String cluePollId) {
        try {
            List<Map<String, Object>> companyList = cluePoolCompanyService.selectCompanyByDistributePermission(cluePollId);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), companyList);
        } catch (Exception e) {
            log.error("cluePoolCompany selectCompanyByDistributePermission error:", e);
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        }
    }


    /**
     * 查询线索池个人使用权限数据回显
     * @param cluePollId
     * @return
     */
    @GetMapping("/selectPoolPersonalPermission")
    public DataResponse selectPoolPersonalPermission(@RequestParam(value="cluePollId",required = true)String cluePollId){
        try {
            List<JSONObject> companyListVO = cluePoolCompanyService.selectPoolPersonalPermission(cluePollId);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), companyListVO);
        } catch (Exception e) {
            log.error("cluePoolCompany selectPoolPersonalPermission error:", e);
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        }
    }

    /**
     * 查询线索池公司使用权限
     */
    @GetMapping("/selectPoolCompanyPermission")
    public DataResponse selectPoolCompanyPermission(@RequestParam(value="cluePollId",required = true)String cluePollId){
        try {
            List<JSONObject> companyList = cluePoolCompanyService.selectPoolCompanyPermission(cluePollId);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), companyList);
        } catch (Exception e) {
            log.error("cluePoolCompany selectPoolCompanyPermission error:", e);
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        }
    }

}
